package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Mapper
public interface OrderMapper {
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("SELECT COUNT(*) FROM orders WHERE status = #{status} AND order_time >= #{min} AND order_time <= #{max}")
    Integer orderCountByStatus(Integer status, LocalDateTime min, LocalDateTime max);

    void update(Orders orders);

    @Select("SELECT * FROM orders WHERE id = #{id}")
    Orders selectById(Long id);

    @Select("select   COUNT(*)  from orders where order_time >= #{min} and order_time <= #{max} and status = #{status}")
    Integer countByTimeAndStatus(LocalDateTime min, LocalDateTime max, Integer status);

    @Select("SELECT COUNT(*) FROM orders WHERE order_time >= #{min} and order_time <= #{max}")
    Integer countAll(LocalDateTime min, LocalDateTime max);

    @Select("SELECT COALESCE(SUM(amount), 0) FROM orders WHERE order_time >= #{min} AND order_time <= #{max} AND status = #{status}")
    Double sumAmount(LocalDateTime min, LocalDateTime max, Integer status);

    @Select("SELECT COUNT(*) FROM orders WHERE status = #{status}")
    Integer countByStatus(Integer status);


    void insert(Orders orders);

    Page<Orders> getByMap(HashMap map);
}
